package com.leetcode;

/**
 * TODO
 *
 * @author lefly
 * @version 1.0
 * @classname No191
 * @description
 * @date 2021/1/28 下午4:22
 */
public class No191 {
    public static void main(String[] args) {
        int n = 3;
        int res = hammingWeight2(n);
        System.out.println(res);
    }

    public static int hammingWeight(int n) {
        int count = 0;
        while (n != 0){
            n = n & (n - 1);
            count++;
        }
        return count;
    }

    public static int hammingWeight2(int n) {
        int count = 0;
        for (int i = 0; i < 32; i++) {
            if((n & 1) == 1){
                count++;
            }
            n >>= 1;
        }
        return count;
    }

}
